package com.usabb.controller;


import java.util.Arrays;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ifast.common.annotation.Log;
import com.ifast.common.base.BaseController;
import com.usabb.domain.CombosItemValueDO;
import com.usabb.service.CombosItemValueService;
import com.ifast.common.utils.Result;

/**
 * 
 * <pre>
 * 套餐条目表
 * </pre>
 * <small> 2019-10-05 10:25:25 | Jory</small>
 */
@Controller
@RequestMapping("/usabb/combosItemValue")
public class CombosItemValueController extends BaseController {
	@Autowired
	private CombosItemValueService combosItemValueService;
	
	@GetMapping()
	@RequiresPermissions("usabb:combosItemValue:combosItemValue")
	String CombosItemValue(){
	    return "usabb/combosItemValue/combosItemValue";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("usabb:combosItemValue:combosItemValue")
	public Result<Page<CombosItemValueDO>> list(CombosItemValueDO combosItemValueDTO){
        Wrapper<CombosItemValueDO> wrapper = new EntityWrapper<>(combosItemValueDTO).orderBy("id", false);
        Page<CombosItemValueDO> page = combosItemValueService.selectPage(getPage(CombosItemValueDO.class), wrapper);
        return Result.ok(page);
	}
	
	@GetMapping("/add")
	@RequiresPermissions("usabb:combosItemValue:add")
	String add(){
	    return "usabb/combosItemValue/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("usabb:combosItemValue:edit")
	String edit(@PathVariable("id") Long id,Model model){
		CombosItemValueDO combosItemValue = combosItemValueService.selectById(id);
		model.addAttribute("combosItemValue", combosItemValue);
	    return "usabb/combosItemValue/edit";
	}
	
	@Log("添加套餐条目表")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("usabb:combosItemValue:add")
	public Result<String> save( CombosItemValueDO combosItemValue){
		combosItemValueService.insert(combosItemValue);
        return Result.ok();
	}
	
	@Log("修改套餐条目表")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("usabb:combosItemValue:edit")
	public Result<String>  update( CombosItemValueDO combosItemValue){
		boolean update = combosItemValueService.updateById(combosItemValue);
		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除套餐条目表")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("usabb:combosItemValue:remove")
	public Result<String>  remove( Long id){
		combosItemValueService.deleteById(id);
        return Result.ok();
	}
	
	@Log("批量删除套餐条目表")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("usabb:combosItemValue:batchRemove")
	public Result<String>  remove(@RequestParam("ids[]") Long[] ids){
		combosItemValueService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}
	
}
